﻿@using DNA.Mvc.Publishing;
@using System.Linq;
@model Category
@{
    Layout = "~/Areas/Publishing/Views/Shared/_ContentLayout.cshtml";
}
<table style="width: 100%;">
    <tr>
        <td>
            <h1 style="overflow: hidden;" class="dna-post-title">
                @if (!string.IsNullOrEmpty(Model.ImageUrl))
                {
                    <img src="@Url.Content(Model.ImageUrl)"  alt="@Model.Title" style="vertical-align: middle;"/>
                }
                <span>@Model.Title</span>
            </h1>
        </td>
        <td style="white-space: nowrap; text-align: right;">
            <ul class="d-horizontal-list">
                @if (Request.IsAuthenticated)
                { 
                    <li>
                        @UIHelper.SubscriptionLink(Ajax, new CategoryWrapper(Model).PermaLink)
                    </li>
                }
                <li>
                    @Ajax.Dna().Link(Url.Action("rss", "Category", new { Area = "Publishing", id = Model.ID })).Text("rss").ImageIcons(@Url.Content("~/Content/Images/rss.png")).GetHtml()
                </li>
                <li>
                    @Ajax.Dna().Link(Url.Action("atom", "Category", new { Area = "Publishing", id = Model.ID })).Text("atom").ImageIcons(@Url.Content("~/Content/Images/rss.png")).GetHtml()
                </li>
            </ul>
        </td>
    </tr>
</table>
<div style="clear: both;">
    @MvcHtmlString.Create(Model.Description)</div>
@{ 
    var category = new CategoryWrapper(Model);
    var articles = category.Articles;
}
<div style="min-height: 550px;">
    @if (string.IsNullOrEmpty(Model.Description))
    {
        foreach (var art in articles)
        {
            if (art.ParentID > 0) { continue; }
            var content = new ArticleWrapper(art).GetGlobalizationContent();
        <h2 class="d-section">
            <a href="@Url.Content("~/publishing/library/t/" + art.ID.ToString() + ".html")"><span>
                @content.Title</span></a>
            <hr />
        </h2>
        <div style="padding-left: 20px; color: #616161;">
            @content.Summary</div>
        }
    }
    @{ 
        var cw = new CategoryWrapper(Model);
        var children = ((IHierarchyData)cw).GetChildren();

        if (((IHierarchyData)cw).HasChildren)
        {
            Ajax.Dna().SiteMap()
                    .Columns(3)
                    .Name("cat_sitemap")
                    .Items(its =>
                    {
                        foreach (CategoryWrapper c in children)
                        {
                            var _title = c.Title;
                            var child = c as IHierarchyData;
                            IHierarchicalEnumerable subCats = child.GetChildren();
                            var subArticles = child.HasChildren ? new List<Article>() : c.Articles.Where(a => a.IsPublished).Take(5).ToList();
                            its.Add().Template(@<text>
        <h2 class="d-section" style="padding-right: 10px;">
            <span><a href="@Url.Content("~/publishing/library/c/" + c.ID.ToString() + ".html")">@_title</a>
            </span>
            <hr />
        </h2>
        @if (child.HasChildren)
        {
            <ul class ="ui-helper-reset">
            @foreach (CategoryWrapper sub in subCats)
            {
                <li><h3 class="d-post-title"><a href="@Url.Content("~/publishing/library/c/" + sub.ID.ToString() + ".html")" title="@sub.Description">@sub.Title</a></h3></li>
            }
            </ul>
        }
        else
        {
            if (subArticles.Count() > 0)
            {
            <ul class ="ui-helper-reset">
            @foreach (var sart in subArticles)
            {
                <li><h3 class="d-section"><a href="@Url.Content("~/publishing/library/t/" + sart.ID.ToString() + ".html")" title="@sart.Title"><span>@Html.Cut(sart.Title,50)</span></a></h3></li>
            }
        </ul>
            }
        }
        </text>);
                        }
                    })
                    .Render();
        }
    }
</div>
<hr />
@WebSiteContext.Current.Web.Copyright
@Html.StartupScripts()
